package com.cat.dataStructure02;

/**
 *   @description https://leetcode.cn/problems/partition-array-into-disjoint-intervals/
 *   @author 曲大人的喵
 *   @create 2025/10/20 11:31
 *   @since JDK17
 */

public class Solution25 {
    public int partitionDisjoint(int[] nums) {
        int n = nums.length, max = nums[0];
        int[] min = new int[n];
        min[n - 1] = nums[n - 1];
        for (int i = n - 2; i > 0; i--) {
            min[i] = Math.min(min[i + 1], nums[i]);
        }
        for (int i = 0; i < n; i++) {
            max = Math.max(max, nums[i]);
            if (max <= min[i + 1]) {
                return i + 1;
            }
        }

        return -1;
    }
}
